package LeetCode.exercise;

public class LC123 {
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int[][] dp1 = new int[n][3], dp2 = new int[n][3];
        dp1[0][0] = -prices[0];
        for(int i = 1; i < 3; i++){
            dp1[0][i] = -0x3f3f3f3f;
            dp2[0][i] = -0x3f3f3f3f;
        }
        for(int i = 1; i < n; i++){
            for(int j = 0; j <= 2; j++){
                dp1[i][j] = Math.max(dp1[i-1][j], dp2[i-1][j] - prices[i]);
                dp2[i][j] = dp2[i-1][j];
                if(j - 1 >= 0){
                    dp2[i][j] = Math.max(dp2[i][j], dp1[i-1][j-1] + prices[i]);
                }
            }
        }
        return Math.max(dp2[n-1][0], Math.max(dp2[n-1][1], dp2[n-1][2]));
    }

    public static void main(String[] args) {
        System.out.println(Integer.MAX_VALUE + 200);
        long i = (long) Integer.MAX_VALUE + 200;
        System.out.println(i);
        System.out.println(-0x3f3f3f3f);
    }
}
